function Enemy(td, name)
{
  var _x;
  var _y;
  var _type;
  var _root;
  var _td;
  var _speed;
  var _energy;
  var _pathIndex;
  var _td;
  var _name;
  var HitEventDispatcher;
  
  this._td = td;
  this._name = name;
  this.HitEventDispatcher = new EventDispatcher();
}

Enemy.prototype.Init = function(td, x, y, et)
{
  this._x = x;
  this._y = y;
  this._type = et;
  this._td = td;
  this._speed = et.speed;
  this._energy = et.energy;
  this._pathIndex = 1;
  
  this._root = new MovieClip();
  
  //hacer - decido el gráfico segun el tipo
  //this._root.DrawCircle(0, 0, 8, '#921515', 1, '#700000', 1);
  this._type.Draw(this._root);
  this._root.x = this._x;
  this._root.y = this._y;
}

Enemy.prototype.Work = function()
{
  var destx = this._td.path[this._pathIndex].x;
  var desty = this._td.path[this._pathIndex].y;
  
  if(this._x >= destx - this._speed &&
     this._x <= destx + this._speed &&
     this._y >= desty - this._speed &&
     this._y <= desty + this._speed)
  {
	//si el enemigo llego al final de su recorrido
    if(this._pathIndex == this._td.path.length - 1)
	{
		//this._pathIndex = 0;
		this._td.onEnemyReachEnd(this);
		return;
	}
    else this._pathIndex++;
    
    var destx = this._td.path[this._pathIndex].x;
    var desty = this._td.path[this._pathIndex].y;
  }
  
  var destx = this._td.path[this._pathIndex].x;
  var desty = this._td.path[this._pathIndex].y;
  
  var ang = Math.atan2(destx - this._root.x, desty - this._root.y);
  var incx = Math.sin(ang) * this._speed;
  var incy = Math.cos(ang) * this._speed;
  
  this._root.x += incx;
  this._root.y += incy;
  
  this._x = this._root.x;
  this._y = this._root.y;
}

Enemy.prototype.Hit = function(misil)
{
  this._energy -= misil._energy;
  if(this._energy <= 0) this._td.EnemyDied(this);
  
  this.HitEventDispatcher.trigger(this);
}

Enemy.prototype.toString = function()
{
  return "[Enemy : " + this._name + "]";
}